package es.ucm.fdi.healthpred.controlador;

import java.awt.EventQueue;
import java.util.Properties;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.jtattoo.plaf.hifi.HiFiLookAndFeel;

import es.ucm.fdi.healthpred.controlador.utils.ConstantsString;

/**
 * Clase que establece el L&amp;F de la aplicaci&oacute;n y su configuraci&oacute;n
 * inicial y ordena al {@link Controlador} que muestre la vista principal.
 * 
 * @since 1.0
 * 
 * @version 1.0
 * 
 * @author &Aacute;lvaro G&oacute;mez Porris
 * @author V&iacute;ctor L&oacute;pez Monte
 * @author Carlos Rodr&iacute;guez Colliga
 * 
 */
public class Main {

	/**
	 * Lanzamiento de la aplicaci&oacute;n.
	 * 
	 * @param args
	 *            No se tienen en cuenta.
	 * 
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					setLookAndFeel();
					BasicConfigurator.configure();
					Logger.getLogger("org.hibernate").setLevel(Level.WARN);
					Controlador.muestraTodosClientes();
					Controlador.show();
				} catch (Exception e) {
					Controlador.vistaPrincipal.ventanaInfo(
							ConstantsString.ERROR_CONEXION,
							ConstantsString.TITULO_ERROR);
					e.printStackTrace();
					Controlador.salir(-1);
				}
			}
		});
	}

	private static void setLookAndFeel() {
		try {
			Properties props = new Properties();
			props.put("logoString", "HealthPred");
			HiFiLookAndFeel.setCurrentTheme(props);
			UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel");
		} catch (Exception ex) {
			ex.printStackTrace();
			try {
				UIManager.setLookAndFeel(UIManager
						.getSystemLookAndFeelClassName());
			} catch (ClassNotFoundException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (UnsupportedLookAndFeelException e1) {
				e1.printStackTrace();
			}
		}
	}

}
